package com.eurasia.assignment.controller.dto;

import java.time.format.DateTimeFormatter;

import com.eurasia.assignment.domain.Assignment;
import com.eurasia.assignment.domain.Project;

import com.eurasia.assignment.domain.ProjectAssignment;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 项目响应DTO
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class ProjectResponse {
    private Long id;
    private String name;
    private String type;
    private String course;
    private String status;
    private Integer points;
    private String creator;
    private String createTime;
    private String updateTime;
    private String startTime;
    private String finishTime;
    private String comment;
    private ProjectAssignment assignment;
    private Long fileId;
    
    private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
    
    /**
     * 将领域对象转换为响应DTO
     */
    public static ProjectResponse fromDomain(Project project, ProjectAssignment assignment) {
        ProjectResponse response = new ProjectResponse();
        response.setId(project.getId());
        response.setName(project.getName());
        response.setType(project.getType());
        response.setCourse(project.getCourse());
        response.setAssignment(assignment);
        
        // 将枚举转换为字符串
        if (project.getStatus() != null) {
            response.setStatus(project.getStatus().toString());
        }
        
        response.setPoints(project.getPoints());
        response.setCreator(project.getCreator());
        response.setFileId(project.getFileId());
        response.setComment(project.getComment());
        
        if (project.getCreateTime() != null) {
            response.setCreateTime(project.getCreateTime().format(FORMATTER));
        }
        
        if (project.getUpdateTime() != null) {
            response.setUpdateTime(project.getUpdateTime().format(FORMATTER));
        }
        
        if (project.getStartTime() != null) {
            response.setStartTime(project.getStartTime().format(FORMATTER));
        }
        
        if (project.getFinishTime() != null) {
            response.setFinishTime(project.getFinishTime().format(FORMATTER));
        }
        
        return response;
    }
} 